package com.x.json;

import com.x.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: JsonController
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.12 23:48
 */

@RequestMapping("json")
@Controller
public class JsonController {

    @ResponseBody //直接返回，不查找视图
    @RequestMapping("data1")
    public User data1(){
        User user = new User();
        user.setName("老二");
        user.setAge(3);
        return user;
    }

    @ResponseBody //直接返回, 不查找视图; 也可以加在类上,内部方法全部被覆盖
    @GetMapping("data2")
    public List<User> data2(){
        User user = new User();
        user.setName("老二");
        user.setAge(3);

        List<User> users = new ArrayList<>();
        users.add(user);
        return users;
    }
}
